package insulinpumpsimulation.com.his.tasks;

import insulinpumpsimulation.SimulationController;
import insulinpumpsimulation.com.his.literal.InsulinPumpLiterals;
import insulinpumpsimulation.com.his.model.BatteryManager;
import java.util.TimerTask;

/**
 *
 * @author Sabahul
 */
public class UpdateSimulatorTask extends TimerTask{

    int i = 0;
    public static Double res_Prog = InsulinPumpLiterals.RESERVOIR_LEVEL_MASTER/InsulinPumpLiterals.RESERVOIR_LEVEL_FULL;
    @Override
    public void run() {
        
        SimulationController uiController = SimulationController.getInstance();
        uiController.setIns_Graph(DurationCalculator.getRunningDuration(),RandomGenerator.showRandomInteger());
        uiController.setIns_Clock(DurationCalculator.getCurrentTime());
        //uiController.setIns_Msg_Area(" ");
        BatteryManager batteryManager = new BatteryManager();
        BasalManager basalManager = new BasalManager();
        
        // Reservoir Progress Bar
         res_Prog = res_Prog - basalManager.getBasalRate() / InsulinPumpLiterals.RESERVOIR_LEVEL_FULL ;
        uiController.setIns_Res_ProgBar(res_Prog);
        
        // Reservoir Lable attached to Progress Bar
       if (res_Prog.toString().length()>4) 
       {
           Double loc_res_Prog = res_Prog*100;
     uiController.setIns_Res_Percentage(loc_res_Prog.toString().substring(0, 4));
       }
       else
       {
      uiController.setIns_Res_Percentage(res_Prog.toString());
       }
        double batteryLevel = batteryManager.getBatteryLevel();
        uiController.setIns_Batt_ProgBar(batteryLevel);
        
        Integer batteryLevelInt = (int) (batteryLevel * 100);

        uiController.setIns_Batt_Percentage(batteryLevelInt.toString());
    }
    
}
